package com.iflytek.autoCompareTool.model;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 测试任务封装
 *
 * @author llchen12
 * @date 2018/6/6
 */
public class Task {

    private Integer id;

    private int size;

    private boolean isCancel;

    private AtomicInteger finishCount;

    private ScheduledFuture<?> controller;

    public Task(Integer id, int size) {
        this.id = id;
        this.size = size;
        isCancel = false;
        finishCount = new AtomicInteger(0);
    }

    public void cancel() {
        if (controller != null) {
            isCancel=true;
            controller.cancel(false);
        }
    }

    public Integer getId() {
        return id;
    }


    public int getSize() {
        return size;
    }


    public boolean isCancel() {
        return isCancel;
    }

//    public void setCancel(boolean cancel) {
//        isCancel = cancel;
//    }

    public double getProgress() {
        return 100.0D * finishCount.get() / size;
    }

    public AtomicInteger getFinishCount() {
        return finishCount;
    }


    public ScheduledFuture<?> getController() {
        return controller;
    }

    public void setController(ScheduledFuture<?> controller) {
        this.controller = controller;
    }

    @Override
    public String toString() {
        return "Task{" +
                "id=" + id +
                ", size=" + size +
                ", isCancel=" + isCancel +
                ", finishCount=" + finishCount +
                '}';
    }
}
